package com.xiaozhi.boot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext run = SpringApplication.run(DemoApplication.class, args);
        String[] names = run.getBeanDefinitionNames();
        for (String name : names) {
            //System.out.println(name);
        }

//        //3、从容器中获取组件
//        Pet tom01 = run.getBean("tom", Pet.class);
//        Pet tom02 = run.getBean("tom", Pet.class);
//        System.out.println("组件："+(tom01 == tom02));
//
//        //4、com.zhitang.demoone.config.MyConfig$$EnhancerBySpringCGLIB$$eff433ef@17461db
//        MyConfig bean = run.getBean(MyConfig.class);
//        System.out.println(bean);
//
//        //如果@Configuration(proxyBeanMethods = true)代理对象调用方法。SpringBoot总会检查这个组件是否在容器中有。
//        //保持组件单实例
//        User user = bean.user01();
//        User user1 = bean.user01();
//        System.out.println(user == user1);
//
//        User user01 = run.getBean("user01", User.class);
//        Pet tom = run.getBean("tom", Pet.class);
//        System.out.println("用户的宠物："+(user01.getPet() == tom));

//        //5、获取组件
//        String[] namesForType = run.getBeanNamesForType(User.class);
//        for (String s : namesForType) {
//            //com.zhitang.demoone.pojo.User
//            //user01
//            System.out.println(s);
//        }
//
//        DBHelper bean1 = run.getBean(DBHelper.class);
//        //ch.qos.logback.core.db.DBHelper@188cbcde
//        System.out.println(bean1);
        boolean user01 = run.containsBean("user01");
        System.out.println(user01);
    }

}
